package com.ssyt.common.utils;

import java.util.List;

public class JdbcPage<T> {
	public JdbcPage(List<T> list, int count, int pageSize, int pageNo) {
		super();
		this.list = list;
		this.count = count;
		this.pageSize = pageSize;
		this.pageNo = pageNo;
	}

	public JdbcPage() {
		super();
	}

	public static final int DEFAULT_PAGE_NO = 1;
	public static final int DEFAULT_PAGE_SIZE = 10;

	/**
	 * 结果集
	 */
	private List<T> list;

	/**
	 * 总记录数
	 */
	private int count;

	/**
	 * 每页显示数
	 */
	private int pageSize;

	/**
	 * 当前是第几页
	 */
	private int pageNo;

	/**
	 * 总页数
	 * 
	 * @return
	 */
	public int getTotalPages() {
		return (int) Math.ceil((double) count / pageSize);
	}

	/**
	 * 首页
	 * 
	 * @return
	 */
	public int getFirst() {
		return 1;
	}

	/**
	 * 尾页
	 * 
	 * @return
	 */
	public int getLast() {
		return getTotalPages();
	}

	/**
	 * 上一页
	 * 
	 * @return
	 */
	public int getPreviousPage() {
		if (pageNo == 1) {
			return getFirst();
		}
		return pageNo - 1;
	}

	/**
	 * 下一页
	 * @return
	 */
	public int getNext() {
		if (pageNo == getTotalPages()) {
			return getTotalPages();
		}
		return pageNo + 1;
	}

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

	

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

}

